<template>
	<view class="">
		<view class="marginTop-20">
			<view class="list flex items-center space-between" @click="loginClick()">
				<view class="flex items-center">
					<image :src="info.image" mode="" class="l_img"></image>
					<view class="l_name">
						{{info.name}}
					</view>
				</view>
			<!-- 	<view class="right">
					当前使用
				</view> -->
			</view>
			<view class="list flex items-center space-between" @click="tabClick(item,index)" v-for="(item,index) in list" 
			:key="index" :class="student_id==item.student_id?'hover':''">
				<view class="flex items-center">
					<image :src="item.avatar" mode="" class="l_img"></image>
					<view class="">
						<view class="l_name">
							{{item.name}}
						</view>
						<view class="l_cont">
							{{item.grade_name}}
						</view>
					</view>
				</view>
				<view class="right">
					当前使用
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		computed,
		defineProps,
		inject,
		defineExpose
	} from 'vue'
	import {
		onShow,
		onLoad
	} from '@dcloudio/uni-app'
	const SelectStudentListApi = inject('SelectStudentList')
		const CutStudentLoginApi = inject('CutStudentLogin')
	const tabClick = (item, index) => {
		uni.navigateTo({
			url: '/pagesA/index/switchTap?student_id='+item.student_id+'&name='+item.name+'&grade_name='+item.grade_name+'&avatar='+item.avatar
		})
	}
	const info = ref({})
	const list = ref([])
	const student_id=ref('')
	onLoad((opt) => {
		student_id.value=opt.student_id
		wx.login({
			success(res) {
				SelectStudentListApi({
					code:res.code
				}).then(res => {
					console.log(res, 999999999)
					list.value = res.list
					info.value = res.info
				})
			}
		})
		
	})
	const loginClick = () => {
		CutStudentLoginApi({
			member_id:info.value.user_id
		}).then(res => {
			console.log(res, 999999999)
			if(res.status==201){
				uni.showToast({
					title:res.msg,
					icon:'none'
				})
			}else{
				uni.setStorageSync('userInfo', res.user)
				uni.setStorageSync('token', res.token)
					uni.setStorageSync('identity','')
				uni.redirectTo({
					url: '/pages/index/index'
				})
			}
			
		})
	}
</script>

<style scoped lang="scss">
	.list {
		width: 626rpx;
		padding: 0 30rpx;
		height: 140rpx;
		background: #F5F5F5;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin: 20rpx auto 0;

		.l_img {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
			margin-right: 16rpx;
		}

		.l_name {
			font-weight: bold;
			font-size: 28rpx;
			color: #333333;
		}

		.l_cont {
			font-weight: bold;
			font-size: 26rpx;
			color: #999999;
		}
.right {
			font-weight: bold;
			font-size: 28rpx;
			color: #51D580;
			opacity: 0;
		}
		
	}
	.hover{
		border: 2rpx solid #51D580;
		.right {
			opacity: 4;
		}
	}
</style>